package com.gcb.socket.p2p;

import java.net.*;
import java.io.*;

public class TestP2PServer {
   public static void main (String[] args) {
       ServerSocket ss = null;
       BufferedReader br = null;
       BufferedReader br2 = null;
       PrintWriter pw = null;
       Socket so=null;
       try {
         ss = new ServerSocket(7777);
             so = ss.accept();
             br = new BufferedReader (new InputStreamReader(so.getInputStream()));
             br2=new BufferedReader (new InputStreamReader(System.in));
             pw = new PrintWriter (new OutputStreamWriter(so.getOutputStream()),true);
             System.out.println("Client:"+br.readLine());
             String st=br2.readLine();
             while (!st.equals("byebye")) {
                 pw.println(st);
                 System.out.println("Server:"+st);
                 System.out.println("Client:"+br.readLine());
                 st=br2.readLine();
             }
          }
        
        catch (IOException e) {
             e.getMessage();
             e.printStackTrace();
          }
        finally {
           try {
             so.close();
             br.close();  
             br2.close();
             pw.close();
           } catch (IOException e) {
                 e.getMessage();
                 e.printStackTrace();
             }
         }
   }
}
